package swingxrcp.framework.client.action;

import java.util.Properties;

import swingxrcp.framework.model.Action;
import swingxrcp.framework.model.exception.ConfigurationException;

/**
 * 客户端Action静态门面
 *
 * @author liangfei
 *
 */
public class ActionFacade {

	// Action数据传输器
	private static Transporter transporter;

	public static void init(Properties properties) {
		String host = properties.getProperty("server.host");
		String port = properties.getProperty("server.port");
		String context = properties.getProperty("server.context");
		String suffix = properties.getProperty("server.suffix");
		transporter = new HttpClientTransporter(host, port == null ? 80 : Integer.parseInt(port), context, suffix);
	}

	/**
	 * 获取Action代理
	 *
	 * @param actionName action名称
	 * @return Action代理
	 */
	public static Action getAction(String actionName) {
		if (transporter == null)
			throw new ConfigurationException("传输组件未初始化!");
		return new ActionProxy(transporter, actionName);
	}

}
